package com.lb.service.impl;

import com.lb.entity.TbMovieType;
import com.lb.dao.TbMovieTypeDao;
import com.lb.service.TbMovieTypeService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (TbMovieType)表服务实现类
 *
 * @author libo
 * @since 2024-09-09 14:09:16
 */
@Service("tbMovieTypeService")
public class TbMovieTypeServiceImpl implements TbMovieTypeService {
    @Resource
    private TbMovieTypeDao tbMovieTypeDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TbMovieType queryById(Integer id) {
        return this.tbMovieTypeDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param tbMovieType 筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<TbMovieType> queryByPage(TbMovieType tbMovieType, PageRequest pageRequest) {
        long total = this.tbMovieTypeDao.count(tbMovieType);
        return new PageImpl<>(this.tbMovieTypeDao.queryAllByLimit(tbMovieType, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tbMovieType 实例对象
     * @return 实例对象
     */
    @Override
    public TbMovieType insert(TbMovieType tbMovieType) {
        this.tbMovieTypeDao.insert(tbMovieType);
        return tbMovieType;
    }

    /**
     * 修改数据
     *
     * @param tbMovieType 实例对象
     * @return 实例对象
     */
    @Override
    public TbMovieType update(TbMovieType tbMovieType) {
        this.tbMovieTypeDao.update(tbMovieType);
        return this.queryById(tbMovieType.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.tbMovieTypeDao.deleteById(id) > 0;
    }
}
